package net.zjitc.lib.Share.volatile1;

public class ShareClass {
    private volatile int n;
    private volatile boolean flag;

    public void product(int i) {
        while (flag) {
        }
        synchronized (this) {
            n = i;
            flag = true;
            System.out.print("\n产生数据" + n);

        }

    }

    public void get() {
        while (!flag) {
        }
        synchronized (this) {
            flag = false;
            System.out.println("\t消费数据" + n);
        }

    }
}
